/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.knezevic.realestate.beans;

import com.knezevic.realestate.Advert;
import com.knezevic.realestate.Identifiable;
import com.knezevic.realestate.Member;
import com.knezevic.realestate.Privilege;
import java.io.Serializable;
import java.util.HashMap;
import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import org.apache.tapestry5.beaneditor.Validate;
import org.apache.tapestry5.ioc.annotations.Inject;

/**
 *
 * @author Nemanja
 */
@Entity
public class MemberBean implements Member,Identifiable, Serializable{

    
    @Id
    @GeneratedValue
    private Long id;
    @Basic
    private String username;
    @Basic
    private String password;
    @Basic
    private String name;
    @Basic
    private String surname;
    @Basic
    private String email;
    @Basic
    private Privilege privilege;
    private HashMap<Long, Advert> adverts;

    @Inject
    public MemberBean() {
    }

    public MemberBean(String username, String password, String name, String surname, String email, Privilege privilege, HashMap<Long, Advert> adverts) {

        this.username = username;
        this.password = password;
        this.name = name;
        this.surname = surname;
        this.email = email;
        this.privilege = privilege;
        this.adverts = adverts;
    }

    public MemberBean(Long id, String username, String password, String name, String surname, String email, Privilege privilege, HashMap<Long, Advert> adverts) {
        this.id = id;
        this.username = username;
        this.password = password;
        this.name = name;
        this.surname = surname;
        this.email = email;
        this.privilege = privilege;
        this.adverts = adverts;
    }

    /**
     * @return the username
     */
    @Validate("required,minlength=2,maxlength=15")
    public String getUsername() {
        return username;
    }

    /**
     * @param username the username to set
     */
    public void setUsername(String username) {
        this.username = username;
    }

    /**
     * @return the password
     */
    @Validate("required,minlength=2,maxlength=15")
    public String getPassword() {
        return password;
    }

    /**
     * @param password the password to set
     */
    public void setPassword(String password) {
        this.password = password;
    }

    /**
     * @return the name
     */
    @Validate("required,minlength=2,maxlength=15")
    public String getName() {
        return name;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @return the surname
     */
    @Validate("required,minlength=2,maxlength=15")
    public String getSurname() {
        return surname;
    }

    /**
     * @param surname the surname to set
     */
    public void setSurname(String surname) {
        this.surname = surname;
    }

    /**
     * @return the email
     */
    @Validate("required,email")
    public String getEmail() {
        return email;
    }

    /**
     * @param email the email to set
     */
    public void setEmail(String email) {
        this.email = email;
    }

    /**
     * @return the privilege
     */
    @Validate("required")
    public Privilege getPrivilege() {
        return privilege;
    }

    /**
     * @param privilege the privilege to set
     */
    public void setPrivilege(Privilege privilege) {
        this.privilege = privilege;
    }

    /**
     * @return the adverts
     */
    public HashMap<Long, Advert> getAdverts() {
        return adverts;
    }

    @Override
    public String toString() {
        return name+" "+surname;
    }

    @Override
    public boolean equals(Object obj) {
        MemberBean m = (MemberBean) obj;
        if(this.username.equalsIgnoreCase(m.getUsername()))
            return true;
        return false;
    }

    /**
     * @param adverts the adverts to set
     */
    public void setAdverts(HashMap<Long, Advert> adverts) {
        this.adverts = adverts;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public long getID() {
        return id;
    }
}
